1
2 import java.sql.Connection;
3 import java.sql.DriverManager;
4 import java.sql.ResultSet;
5 import java.sql.Statement;

6
7 /*
8  * To change
this license header, choose License Headers in Project Properties.
9  * To change
this template file, choose Tools | Templates
10  * and open the template
in the editor.
11  */
12
13 /**
14  *
15  * @author MY LAPI
16  */

17 public
class AdminLogin extends javax.swing.JFrame {
18
19     
/**
20      * Creates
new form AdminLogin
21      */

22     
public AdminLogin() {
23         initComponents();
24     }
25
26     
/**
27      * This method
is called from within the constructor to initialize the form.
28      * WARNING: Do NOT modify
this code. The content of this method is always
29      * regenerated
by the Form Editor.
30      */

31     @SuppressWarnings(
"unchecked")
32     
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
33     
private void initComponents() {
34
35         jLabel1 =
new javax.swing.JLabel();
36         jLabel2 =
new javax.swing.JLabel();
37         jLabel3 =
new javax.swing.JLabel();
38         jTextField2 =
new javax.swing.JTextField();
39         jButton1 =
new javax.swing.JButton();
40         jLabel4 =
new javax.swing.JLabel();
41         jPasswordField1 =
new javax.swing.JPasswordField();
42
43         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
44
45         jLabel1.setFont(
new java.awt.Font("Arial Unicode MS", 0, 24)); // NOI18N
46         jLabel1.setText(
"ADMIN PANEL");
47
48         jLabel2.setFont(
new java.awt.Font("Arial Unicode MS", 0, 18)); // NOI18N
49         jLabel2.setText(
"UserName");
50
51         jLabel3.setFont(
new java.awt.Font("Arial Unicode MS", 0, 18)); // NOI18N
52         jLabel3.setText(
"Password");
53
54         jTextField2.addActionListener(
new java.awt.event.ActionListener() {
55             
public void actionPerformed(java.awt.event.ActionEvent evt) {
56                 jTextField2ActionPerformed(evt);
57             }
58         });
59
60         jButton1.setFont(
new java.awt.Font("Arial Unicode MS", 0, 18)); // NOI18N
61         jButton1.setText(
"Login");
62         jButton1.addActionListener(
new java.awt.event.ActionListener() {
63             
public void actionPerformed(java.awt.event.ActionEvent evt) {
64                 jButton1ActionPerformed(evt);
65             }
66         });
67
68         jLabel4.setForeground(
new java.awt.Color(255, 0, 0));
69
70         javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
71         getContentPane().setLayout(layout);
72         layout.setHorizontalGroup(
73             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
74             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
75                 .addGap(
31, 31, 31)
76                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
77                     .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE,
101, javax.swing.GroupLayout.PREFERRED_SIZE)
78                     .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE,
101, javax.swing.GroupLayout.PREFERRED_SIZE))
79                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
58, Short.MAX_VALUE)
80                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
81                     .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE,
192, javax.swing.GroupLayout.PREFERRED_SIZE)
82                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
83                         .addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING)
84                         .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE,
166, Short.MAX_VALUE)))
85                 .addGap(
25, 25, 25))
86             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
87                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
88                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
89                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
90                         .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE,
202, javax.swing.GroupLayout.PREFERRED_SIZE)
91                         .addGap(
94, 94, 94))
92                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
93                         .addComponent(jButton1)
94                         .addGap(
103, 103, 103))))
95         );
96         layout.setVerticalGroup(
97             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
98             .addGroup(layout.createSequentialGroup()
99                 .addContainerGap()
100                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE,
37, javax.swing.GroupLayout.PREFERRED_SIZE)
101                 .addGap(
24, 24, 24)
102                 .addComponent(jLabel4)
103                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
104                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
105                     .addComponent(jLabel2)
106                     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
25, javax.swing.GroupLayout.PREFERRED_SIZE))
107                 .addGap(
25, 25, 25)
108                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
109                     .addComponent(jLabel3)
110                     .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE,
25, javax.swing.GroupLayout.PREFERRED_SIZE))
111                 .addGap(
45, 45, 45)
112                 .addComponent(jButton1)
113                 .addContainerGap(
56, Short.MAX_VALUE))
114         );
115
116         pack();
117     }
// </editor-fold>//GEN-END:initComponents
118
119     
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
120         
// TODO add your handling code here:
121     }
//GEN-LAST:event_jTextField2ActionPerformed
122
123     
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
124        
try{
125             Class.forName(
"com.mysql.jdbc.Driver").newInstance();
126             Connection cn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/bank","root","");
127             
128             Statement smt=cn.createStatement();
129             ResultSet rs=smt.executeQuery(
"select aid from admin where uname='"+jTextField2.getText()+"' and password='"+jPasswordField1.getText()+"'");
130            
131             
if(rs.next()){
132         AdminLogin pb1=
new AdminLogin();
133                 AdminDesh pb2=
new AdminDesh();
134                 pb1.setVisible(
false);
135                 pb2.setVisible(
true);
136                 dispose();
137             }
else{
138                 jLabel4.setText(
"** Wrong Username OR Password **");
139             }
140         }
catch(Exception e){jLabel4.setText(e.getMessage());}
141     }
//GEN-LAST:event_jButton1ActionPerformed
142
143     
/**
144      * @param args the command line arguments
145      */

146     
public static void main(String args[]) {
147         
/* Set the Nimbus look and feel */
148         
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
149         
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
150          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
151          */

152         
try {
153             
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
154                 
if ("Nimbus".equals(info.getName())) {
155                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
156                     
break;
157                 }
158             }
159         }
catch (ClassNotFoundException ex) {
160             java.util.logging.Logger.getLogger(AdminLogin.
class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
161         }
catch (InstantiationException ex) {
162             java.util.logging.Logger.getLogger(AdminLogin.
class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
163         }
catch (IllegalAccessException ex) {
164             java.util.logging.Logger.getLogger(AdminLogin.
class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
165         }
catch (javax.swing.UnsupportedLookAndFeelException ex) {
166             java.util.logging.Logger.getLogger(AdminLogin.
class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
167         }
168         
//</editor-fold>
169
170         
/* Create and display the form */
171         java.awt.EventQueue.invokeLater(
new Runnable() {
172             
public void run() {
173                 
new AdminLogin().setVisible(true);
174             }
175         });
176     }
177
178     
// Variables declaration - do not modify//GEN-BEGIN:variables
179     
private javax.swing.JButton jButton1;
180     
private javax.swing.JLabel jLabel1;
181     
private javax.swing.JLabel jLabel2;
182     
private javax.swing.JLabel jLabel3;
183     
private javax.swing.JLabel jLabel4;
184     
private javax.swing.JPasswordField jPasswordField1;
185     
private javax.swing.JTextField jTextField2;
186     
// End of variables declaration//GEN-END:variables
187 }


Gõ tìm kiếm nhanh...